﻿using KZ400B.Data;
/* ==============================================================================
 * Copyright (c) ShangXichao All right reserved. 
 * 类名称：AxleActionStatus
 * 类描述：
 * 创建人：SXC
 * 创建时间：2014/4/26 18:38:51
 * 修改人：
 * 修改时间：
 * 修改备注：
 * @version 1.0
 * ==============================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KZ400B
{
    public class AxleActionStatus : PropertyChangedBase
    {
        public AxleActionStatus(string axleName)
        {
            m_AxleName = axleName;
            m_VZeroIsSeted = false;
            m_canVZeroSet = false;
        }
        string m_AxleName;
        AxleActions m_currentAction;

        public AxleActions CurrentAction
        {
            get { return m_currentAction; }
            set { 
                
                    AxleActions tmpAct = value;
                    if (m_currentAction == AxleActions.ToZero
                        && tmpAct == AxleActions.Stop
                        && !m_VZeroIsSeted
                        )
                    {
                        CanVZeroSet = true;
                    }
                    else
                    {
                        if (tmpAct == AxleActions.ToZero
                            || tmpAct == AxleActions.Stop
                            || tmpAct == AxleActions.Run
                            || tmpAct == AxleActions.RelativeZero
                            )
                        {
                            CanVZeroSet = false;
                        }
                    }
                    m_currentAction = tmpAct; 
            }
        }

        bool m_VZeroIsSeted;

        public bool VZeroIsSeted
        {
            get { return m_VZeroIsSeted; }
            set {
                m_VZeroIsSeted = value;
                
            this.NotifyPropertyChanged(n => VZeroIsSeted);

            try
            {
                MySetting.setVZeroSetStoreAxleValue(m_AxleName, m_VZeroIsSeted);
                MySetting.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine("VZeroIsSeted => {0} error:{1} => {2}",m_VZeroIsSeted,ex.Message,ex.StackTrace);
            }
            }
        }

        bool m_canVZeroSet; 
        public bool CanVZeroSet
        {
            get { return m_canVZeroSet; }
            protected set{
                if (m_canVZeroSet != value)
                {
                    m_canVZeroSet = value;
                    this.NotifyPropertyChanged(n => CanVZeroSet);
                }
            }
        }
    }
}
